<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%@ include file="/common/operatehistory.jsp"%>
<%@ include file="/common/code.jsp"%>
<%@ include file="/common/user.jsp"%>
<%
    // 关注医生，患者，科室
	String code = input.getDesc("code", "").trim();
	Integer category = input.getInt("category");
	if (!category.equals(SECTION_DOCTOR) && !category.equals(SECTION_PATIENT) && !category.equals(DEPT_CATEGORY)) {
		  Tools.encryptPrint(out, new Message(30041, "不支持关注的类型"));
		  return;
	}
	OperateHistory oh = OperateHistory.fromMap(parameters, OperateHistory.class);
    oh.setUid(token.getUid() + "");
    oh.setCategory(category);
    oh.setOperate(ATTENTION);
	if (category.equals(SECTION_DOCTOR)) {
		OperateHistory ohDept = OperateHistory.fromMap(parameters, OperateHistory.class);
		ohDept.setUid(token.getUid() + "");
		ohDept.setCategory(DEPT_CATEGORY);
		ohDept.setOperate(ATTENTION);
		List<String> list = QBuilder.db("basedb").select("concat(h.id, '')").from("User as u, Hospital as h").where(new Where("h.hospital=u.deptId").and("u.id=", oh.getOid())).query().getResultObj();
		if (!isEmpty(list)) {
			ohDept.setOid(list.get(0));	
			operate(ohDept, false);
		}
		User user = userByUid(Tools.getInt(oh.getOid()));
		if (user == null || Tools.getDesc(user.getJson("role")).equals("2") ) {
			 Tools.encryptPrint(out, new Message(30041, "只能关注医生"));
			 return;
		}
	}
    Tools.encryptPrint(out, operate(oh, false));
%>
